home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWTxtBuf.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  3.8 KB  |  131 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTxtBuf.h
  4. //    Release Version:    $ 1.0d11 $
  5. //    Modifed by MEB to support non-single-byte characters
  6. //
  7. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  8. //
  9. //========================================================================================
  10.  
  11. #ifndef FWTXTBUF_H
  12. #define FWTXTBUF_H
  13.  
  14. #ifndef FWGRDEF_H
  15. #include "FWGrDef.h"
  16. #endif
  17.  
  18. // ----- Foundation Layer -----
  19.  
  20. #ifndef FWSTRING_H
  21. #include "FWString.h"
  22. #endif
  23.  
  24. #ifndef FWEXCLIB_H
  25. #include "FWExcLib.h"
  26. #endif
  27.  
  28. // ----- OpenDoc Includes -----
  29.  
  30. #ifndef _ODTYPES_
  31. #include <ODTypes.h>
  32. #endif
  33.  
  34. #if FW_LIB_EXPORT_PRAGMAS
  35. #pragma lib_export on
  36. #endif
  37.  
  38. //========================================================================================
  39. // CLASS FW_CPrivTextBuffer
  40. //========================================================================================
  41. //    Internal class used by the graphic component to read text from strings or text readers
  42. //    for text measurement/drawing.
  43. //    Text is sliced up into lines (terminated by newLine character)
  44. //    We try to avoid dynamic memory allocation as much as possible
  45.  
  46. class FW_CPrivTextBuffer FW_AUTO_DESTRUCT_OBJECT
  47. {
  48. public:
  49.     FW_CPrivTextBuffer(const FW_CString* string);
  50.         // Constructs a buffer using a string as a source.
  51.         // No data copying occurs.
  52.         
  53.     FW_CPrivTextBuffer(FW_CTextReader* reader);
  54.         //     Constructs a buffer using a text reader as a source.
  55.         //    No data copying occurs if the first block read from the reader
  56.         //    is as large as the whole data structure;
  57.         //    otherwise, data is copied into a temporary contiguous buffer line by line.
  58.         
  59.     virtual ~ FW_CPrivTextBuffer();
  60.     
  61.     FW_ByteCount         GetTotalLength() const;
  62.         // returns the total length (in bytes) of the whole data structure
  63.     
  64.     FW_Boolean             IsDone() const;
  65.         // returns TRUE when there is nothing left to read
  66.         
  67.     void                 GetNextLine();
  68.         // reads the next line from the buffer
  69.         
  70.     const FW_Byte*         GetCurrentLine() const;
  71.         // returns a pointer to the current contiguous line of text
  72.         
  73.     FW_ByteCount         GetCurrentLineLength() const;
  74.         // returns length of the current line, in bytes
  75.         
  76. private:
  77.     void                 ResetBuffer(FW_ByteCount size = 256);
  78.     void                 AppendCharacterToBuffer(FW_Char c);
  79.     
  80.     FW_CPrivTextBuffer(const FW_CPrivTextBuffer& otherBuffer);
  81.     FW_CPrivTextBuffer& operator=(const FW_CPrivTextBuffer& otherBuffer);
  82.         // Copy constructor and assignment operator not valid for this class.
  83.  
  84. private:
  85.     const FW_CString*         fString;
  86.     FW_CTextReader*         fReader;
  87.     
  88.     FW_Byte*                 fCurrentLine;
  89.     FW_ByteCount             fCurrentLineLength;
  90.     
  91.     FW_Boolean                 fIsDone;        // are we there yet?
  92.     
  93.     // ----- the stuff below is used when we read a FW_CTextReader
  94.     
  95.     static FW_Byte             gStaticBuffer[];
  96.     static unsigned short     gStaticBufferUseCount;
  97.         //     To save stack space, the static buffer is, well, static
  98.         //    however, this class needs to be re-entrant (for printing), so
  99.         //    we maintain a semaphore which tells us whether the buffer is in use
  100.     
  101.     FW_Byte*                 fDynamicBufferBase;
  102.     FW_ByteCount             fDynamicBufferSize;
  103.         // if the static buffer is busy, or if it is too small, we allocate a
  104.         // dynamic buffer
  105.         
  106.     FW_ByteCount             fCurrentBufferSize;
  107.         // the current size of the current buffer
  108.     
  109. };
  110.  
  111. //========================================================================================
  112. // Global Method PrivGetStringSegment
  113. //========================================================================================
  114.  
  115. FW_Boolean    PrivGetStringSegment(ODPlatformCanvas platformCanvas,
  116.                                 const char* str,
  117.                                     FW_ByteCount len,
  118.                                     FW_BytePosition& segStart,
  119.                                     FW_ByteCount& segLen,
  120.                                     FW_PlatformCoordinate maxWidth,
  121.                                    FW_PlatformCoordinate& actualWidth,
  122.                                     FW_Boolean wordWrap,
  123.                                     FW_Boolean wordBreak);
  124.  
  125. #if FW_LIB_EXPORT_PRAGMAS
  126. #pragma lib_export off
  127. #endif
  128.  
  129. #endif
  130.  
  131.